<template>
  <div class="EmergencyList">
    <div class="flex location-wrap">
      <span class="white">当前位置：</span>
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/EDManagement' }">应急处置 </el-breadcrumb-item>
        <el-breadcrumb-item :to="{ path: '/ResourceAllocation' }">资源调配</el-breadcrumb-item>
        <el-breadcrumb-item>{{ this.applyType == 1 ? "队伍" : this.applyType == 2 ? "车辆" : this.applyType == 3 ? "装备" :
          "物资" }}调配</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="box">
      <!-- 列表筛选 -->
      <filterTitle @query="onSubmit(form)" @reset="resetForm" :form="form" @node-click="handleSelectTree"
        :formData="formData" labelWidth="140px">
        <!-- <el-form slot="filter" class="form" ref="form" :model="form" inline size="small" label-width="140px">
          <el-form-item :label="item.label+'：'" v-for="(item, index) in formData" :key="index" :prop="item.id">
            <LsdForm :compData="item" :form="form" @node-click="handleSelectTree(arguments,item)" />
          </el-form-item>
        </el-form> -->
      </filterTitle>
      <!-- 列表表格 -->
      <LsdTable slot="gjxm" :paginationAtrrs="paginationAtrrs" :compRef="table.compRef" @pageChange="handleSizeChange($event,form)"
        ref="gjxm" :columns="table.columns" :title="table.title" :actions="table.actions" :tableData="table.tableData"
        :tableAttr="table.tableAttr" :isShowPage="table.isShowPage" :isSelectFlag="table.isSelectFlag"
        :isSequenceFlag="table.isSequenceFlag" @onActionClick="onActionClick" />
    </div>
    <!-- 弹窗信息 -->
    <LsdDialog :dialogConfig="requestDialog.dialogConfig" @handleBtn="handleBtn" @close="cancel"
      v-if="requestDialog.dialogConfig.isShow">
      <el-form :inline="true" :model="dialogForm" size="small" ref="dialogForm" :rules="requestDialog.rules"
        slot="dialog">
        <LsdDialogTitle :titleConfig="requestDialog.titleConfig" :activeNames="activeNames"
          :disableKeys="requestDialog.disableKeys">
          <DialogForm2 ref="formComponent1" slot="slot1" :form="dialogForm" :formConfig="requestDialog.formConfig1"
            @changeEvent="changeMld" />
          <DialogForm2 ref="formComponent2" slot="slot2" :form="dialogForm" :formConfig="requestDialog.formConfig2"
            @handleNodeClick="handleCascaderChange" @changeEvent="changeLxr" />
          <div slot="slot3" class="tableDiv">
            <DialogForm2 ref="formComponent3" :formConfig="requestDialog.formConfig3" :form="dialogForm" />
            <LsdTable :compRef="requestDialog.formConfig3.table.compRef"
              :autoHeight="requestDialog.formConfig3.table.autoHeight" :columns="requestDialog.formConfig3.table.columns"
              :tableData="dialogForm.tableData" :tableAttr="requestDialog.formConfig3.table.tableAttr"
              :isSequenceFlag="requestDialog.formConfig3.table.isSequenceFlag" />
          </div>
          <DialogForm2 ref="formComponent4" slot="slot4" :form="dialogForm" :formConfig="requestDialog.formConfig4" />
          <DialogForm2 ref="formComponent5" slot="slot5" :form="dialogForm" :formConfig="requestDialog.formConfig5" />
          <DialogForm2 ref="formComponent6" slot="slot6" :form="dialogForm" :formConfig="requestDialog.formConfig6" />
        </LsdDialogTitle>
      </el-form>
    </LsdDialog>

  </div>
</template>

<script>
// import { cloneDeep } from "lodash";
import { showTime } from "@/lib";
import { GetRequestList, SaveOrSubmit, ResourceUpdate, GetApplyDetail, ResourceDeleted, GetDemandLevel, GetListEquipmentType, DispacthApproveOne, DispacthApproveTwo } from "@/api/EmergencyDisposal/zydp.js";
import { getUnitAndNextUnit, GetResponse, getAccountOrgById, getBatchDicList, getUpDepartment } from "@/api/common.js";
import { TeamFormDialog, CarFormDialog, EquipmentFormDialog, MaterialFormDialog, bianji, shenpi } from "./RequestDialog.js";
// import { flowSubmit } from "@/utils/flow";
export default {
  name: "ResourceRequestList",
  components: {},
  data() {
    return {
      roleCode: JSON.parse(sessionStorage.getItem("role")).roleCode, // 当前登录人id
      UserInfo: {
        userName: JSON.parse(sessionStorage.getItem("account")) && JSON.parse(sessionStorage.getItem("account")).realName || "",
        userUnit: JSON.parse(sessionStorage.getItem("org")) && JSON.parse(sessionStorage.getItem("org")).orgName || ""
      },
      dwbmName: sessionStorage.getItem("dwbmName"),
      orgId: JSON.parse(sessionStorage.getItem("org")).orgId, // 当前登录人id
      ssbmId: JSON.parse(sessionStorage.getItem("org")).ssbmId, // 当前登录人id
      // 筛选信息
      formData: [
        {
          elType: "input",
          id: "sourceInfo",
          label: "响应命令单",
          attrs: {
            value: "",
            size: "small",
            "collapse-tags": true,
            clearable: true
          }
        },
        {
          elType: "input",
          id: "resourceApplyName",
          label: "资源申请单",
          attrs: {
            value: "",
            size: "small",
            "collapse-tags": true,
            clearable: true
          }
        },
        {
          elType: "lsdTree",
          id: "acceptUnit",
          name: "acceptUnitId",
          treeRef: "treeRef",
          keyWord: "keyWord",
          commonClick: true,
          label: "受理单位及部门",
          attrs: {
            value: "",
            clearable: true,
            "collapse-tags": true
          },
          options: {
            attrs: {
              value: ""
            }
          },
          treeData: {
            attrs: {
              data: []
            },
            props: {
              children: "children",
              label: "orgName",
              value: "id"
            }
          }
        },
        {
          elType: "lsdTree",
          id: "applyUnit",
          name: "applyUnitId",
          treeRef: "treeRef",
          keyWord: "keyWord",
          commonClick: true,
          label: "申请单位",
          attrs: {
            value: "",
            clearable: true,
            "collapse-tags": true
          },
          options: {
            attrs: {
              value: ""
            }
          },
          treeData: {
            attrs: {
              data: []
            },
            props: {
              children: "children",
              label: "orgName",
              value: "id"
            }
          }
        },
        {
          elType: "dateTimePicker",
          id: "applyTime",
          label: "申请时间",
          attrs: {
            value: "",
            size: "small",
            type: "datetimerange",
            "value-format": "yyyy-MM-dd HH:mm:ss",
            clearable: true
          }
        },
        {
          elType: "select",
          id: "applyEvel",
          label: "需求等级",
          attrs: {
            value: "",
            size: "small",
            "collapse-tags": true,
            clearable: true
          },
          options: []
        },
        {
          elType: "select",
          id: "applyStatus",
          label: "状态",
          attrs: {
            value: "",
            size: "small",
            clearable: true,
            "collapse-tags": true
          },
          options: [
            {
              label: "编辑中",
              value: "1"
            },
            {
              label: "待审批",
              value: "2"
            },
            {
              label: "已审批",
              value: "3"
            },
            {
              label: "驳回",
              value: "4"
            }
          ]
        }
      ],
      // 表格信息
      table: {
        compRef: "zysq",
        isSequenceFlag: true,
        isShowPage: true,
        resetFlag: true,
        loading: false,
        title: "队伍申请单列表",
        actions: [
          {
            id: "dialogVisible",
            text: "新增",
            type: "primary",
            btnAttr: { size: "small" }
          }
        ],
        tableData: [],
        columns: [
          {
            prop: "resourceApplyName",
            label: "资源申请单",
            align: "left",
            "min-width": "230px",
            render: (h, { row }) => {
              return (
                <div>
                  {
                    <span
                      class='commonTableStyle'
                      style='width:100%'
                      {...{
                        on: {
                          click: () => {
                            this.detailList(row.id);
                          }
                        }
                      }}
                    >
                      {row.resourceApplyName}
                    </span>
                  }
                </div>
              );
            }
          },
          {
            prop: "eventName",
            label: "事件类别",
            align: "center"
          },
          {
            prop: "responseLvName",
            label: "事件级别",
            align: "center"
          },
          {
            prop: "effectRange",
            label: "影响范围",
            align: "left"
          },
          {
            prop: "effectTime",
            label: "影响时间",
            align: "left",
            "min-width": "120px"
          },
          {
            prop: "acceptUnit",
            label: "受理单位及部门",
            align: "left",
            "min-width": "120px"
          },
          {
            prop: "applyUnit",
            label: "申请单位",
            align: "left",
            "min-width": "120px"
          },
          {
            prop: "applyTime",
            label: "申请时间",
            align: "left",
            "min-width": "120px"
          },
          {
            prop: "applyEvelName",
            label: "需求等级",
            align: "center",
            "min-width": "120px"
          },
          {
            prop: "sourceInfo",
            label: "响应命令单",
            align: "center",
            "min-width": "230px",
            render: (h, { row }) => {
              return (
                <div>
                  {
                    <span
                      class='commonTableStyle'
                      style='width:100%'
                      {...{
                        on: {
                          click: () => {
                            this.goSourceInfo(row.sourceInfoId);
                          }
                        }
                      }}
                    >
                      {row.sourceInfo}
                    </span>
                  }
                </div>
              );
            }
          },
          {
            prop: "applyStatusName",
            label: "状态",
            align: "center",
            "min-width": "100px"
          },
          {
            prop: "cz",
            label: "操作",
            align: "center",
            fixed: "right",
            "min-width": "100px",
            render: (h, { row }) => {
              const tbPower = this.common.isHasPower("tbr");
              const userId = JSON.parse(sessionStorage.getItem("account")).id;
              return (
                <div>
                  {
                    <span
                      style='color:#3561fd;cursor:pointer;text-decoration: underline;'
                      {...{
                        on: {
                          click: () => {
                            this.handleEdit(row.id);
                          }
                        }
                      }}
                    >
                      {[1, 4].includes(row.applyStatus) && tbPower ? "编辑" : ""}
                    </span>
                  }
                  {
                    <span
                      style='color:#3561fd;cursor:pointer;text-decoration: underline;'
                      class={[1, 4].includes(row.applyStatus) ? "marginL10" : ""}
                      {...{
                        on: {
                          click: () => {
                            this.deleted(row.id);
                          }
                        }
                      }}
                    >
                      {[1, 4].includes(row.applyStatus) && tbPower ? "删除" : ""}
                    </span>
                  }
                  {
                    <span
                      style='color:#3561fd;cursor:pointer;text-decoration: underline;'
                      {...{
                        on: {
                          click: () => {
                            this.Approval(row.id, row.applyStatus);
                          }
                        }
                      }}
                    >
                      {[2].includes(row.applyStatus) && [row.oApprovalId].includes(userId) ? "审批" : ""}
                      {[5].includes(row.applyStatus) && [row.tApprovalId].includes(userId) ? "审批" : ""}
                    </span>
                  }
                </div>
              );
            }
          }
        ],
        tableAttr: {
          stripe: false,
          border: true,
          fit: true,
          "show-header": true,
          "highlight-current-row": true,
          "cell-style": {
            "font-size": "16px"
          },
          "header-cell-style": {
            "text-align": "center",
            "background-color": "#B1C8F9",
            border: "1px solid #ccc",
            "font-size": "16px"
          }
        }
      },
      paginationAtrrs: {
        total: 0,
        "background": true,
        layout: "prev, pager, next",
        "current-page": 1,
        "page-size": 10
      },
      multipleSelection: [],
      requestDialog: {
        dialogConfig: {
          title: "队伍申请单",
          destroyOnClose: true,
          isShow: false,
          btnList: [
            {
              name: "提交",
              type: "primary",
              id: "submit",
              size: "small"
            },
            {
              name: "保存",
              id: "submit",
              size: "small"
            },
            {
              name: "取消",
              id: "cancel",
              size: "small"
            }
          ]
        }
      },
      form: {
        sourceInfo: "", // 响应命令单
        resourceApplyName: "", // 资源申请单
        acceptUnit: "",
        acceptUnitId: "", // 受理单位及部门
        applyUnit: "",
        applyUnitId: "", // 申请单位
        applyStartTime: "", // 开始时间
        applyEndTime: "", // 结束时间
        applyEvel: "", // 需求等级
        applyStatus: "" // 状态
      },
      dialogForm: {
        sourceInfoId: "",
        resourceApplyName: "",
        applyUnit: "",
        applyUnitId: "",
        applyEvel: "",
        acceptUnit: "",
        acceptUnitId: "",
        destination: "",
        peopleCount: "",
        expectArrivalTime: "",
        contact: "",
        contactId: "",
        contactWay: "",
        applyDescription: "",
        oApprovalId: "",
        oApprovalName: "",
        tApprovalId: "",
        tApprovalName: "",
        creator: "",
        creatorUnit: "",
        createTime: "",
        approvalOpinion: "",
        approvalDept: "",
        approvalUser: "",
        approvalTime: "",
        tApprovalUser: "",
        tApprovalDept: "",
        tApprovalTime: "",
        tableData: []
      },
      addOredit: 0, // 编辑还是新增
      total: 0,
      applyType: 1, // 资源类型
      applyStatus: "", // 申请单状态
      pageNum: 1,
      pageSize: 10,
      activeNames: ["1", "2", "3", "4", "5", "6"],
      mldName: "", // 命令单
      requestListId: "",
      Usersoptions: [],
      selectOptions: {
        teamType: [], // 队伍类型
        teamMajor: [], // 队伍专业
        memberMajor: [], // 人员专业
        memberAbilityName: [], // 特种作业能力
        vehicleProperties: [], // 车辆性质
        vehicleUsage: [], // 车辆用途
        vehicleType: [], // 车辆类型
        zbLargeCategory: [], // 装备大类
        zbSmallCategory: [], // 装备小类
        parameters: [], // 型号参数
        wzLargeCategory: [], // 物资大类
        middleCategory: [], // 物资中类
        wzSmallCategory: [] // 物资小类
      },
      // 需求明细必填校验
      tableForm: {
        rules: {
          teamTypeCode: [
            { required: true, message: "请选择队伍类型", trigger: "change" }
          ],
          teamMajorCode: [
            { required: true, message: "请选择队伍专业", trigger: "change" }
          ],
          memberMajorCode: [
            { required: true, message: "请选择人员专业", trigger: "change" }
          ],
          memberAbilityCode: [
            { required: true, message: "请选择特种作业能力", trigger: "change" }
          ],
          vehiclePropertiesCode: [
            { required: true, message: "请选择车辆性质", trigger: "change" }
          ],
          vehicleUsageCode: [
            { required: true, message: "请选择车辆用途", trigger: "change" }
          ],
          vehicleTypeCode: [
            { required: true, message: "请选择车辆类型", trigger: "change" }
          ],
          largeCategoryCode: [
            { required: true, message: "请选择装备或物资大类", trigger: "change" }
          ],
          smallCategoryCode: [
            { required: true, message: "请选择装备或物资小类", trigger: "change" }
          ],
          parametersCode: [
            { required: true, message: "请选择型号参数", trigger: "change" }
          ],
          middleCategoryCode: [
            { required: true, message: "请选择物资中类", trigger: "change" }
          ]
        }
      }
    };
  },
  watch: {
    // 侦听路由器参数变化
    $route: {
      handler(newVal, oldval) {
        if (newVal.query !== oldval.query) {
          this.switchRoute();
        }
      }
    },
    "dialogForm.tableData": {
      handler(val) {
        let nums = 0;
        if (val.length) {
          nums = val.reduce((prev, cur) => {
            return { count: Number(prev.count) + Number(cur.count) };
          }, { count: 0 });
        }
        this.dialogForm.peopleCount = nums.count;
      },
      deep: true
    }
  },
  mounted() {
    this.switchRoute();
  },
  methods: {
    switchRoute() {
      if (this.$route.query.type === "team") {
        this.applyType = 1;
        this.requestDialog = TeamFormDialog(this);
        this.dialogForm.tableData = this.requestDialog.formConfig3.table.tableData;
        this.table.title = "队伍申请单列表";
      } else if (this.$route.query.type === "car") {
        this.applyType = 2;
        this.requestDialog = CarFormDialog(this);
        this.dialogForm.tableData = this.requestDialog.formConfig3.table.tableData;
        this.table.title = "车辆申请单列表";
      } else if (this.$route.query.type === "equipment") {
        this.applyType = 3;
        this.requestDialog = EquipmentFormDialog(this);
        this.dialogForm.tableData = this.requestDialog.formConfig3.table.tableData;
        this.table.title = "装备申请单列表";
      } else if (this.$route.query.type === "material") {
        this.applyType = 4;
        this.requestDialog = MaterialFormDialog(this);
        this.dialogForm.tableData = this.requestDialog.formConfig3.table.tableData;
        this.table.title = "物资申请单列表";
      }
      this.GetRequestLists();
      this.resetForm();
      this.getFormInput();
    },
    // 获取列表信息
    async GetRequestLists() {
      const parmas = {
        pageNum: this.pageNum,
        pageSize: this.pageSize,
        applyType: this.applyType
      };
      const res = await GetRequestList(parmas);
      this.table.tableData = res.data;
      this.paginationAtrrs.total = res.total;
    },
    // 获取表单下拉框
    getFormInput() {
      GetResponse({ orgId: this.orgId }).then(res => { // 响应命令单
        const option = res.map((item) => {
          return {
            label: item.responseName,
            value: item.id
          };
        });
        this.requestDialog.formConfig1.formData[0].options = option;
      });
      this.requestDialog.formConfig2.formData.forEach((item) => {
        if (item.prop === "applyEvel") { // 需求等级
          GetDemandLevel().then(res => {
            const option = res.map((i) => {
              return {
                label: i.name,
                value: Number(i.code)
              };
            });
            item.options = option;
          });
        }
        if (item.prop === "acceptUnit") {
          getUpDepartment().then(res => {
            item.treeData.data = res;
          });
        }
      });
      this.formData.forEach(item => {
        if (item.id === "acceptUnit") {
          getUpDepartment().then(res => {
            item.treeData.attrs.data = res;
          });
        }
        if (item.id === "applyUnit") {
          getUnitAndNextUnit({ orgId: this.orgId }).then(res => {
            item.treeData.attrs.data = res;
          });
        }
        if (item.id === "applyEvel") { // 需求等级
          GetDemandLevel().then(res => {
            const option = res.map((i) => {
              return {
                label: i.name,
                value: Number(i.code)
              };
            });
            item.options = option;
          });
        }
      });
      this.getDemandSelect();
      console.log(this.selectOptions);
    },
    async getDemandSelect() {
      if (this.applyType == 1) {
        const res = await getBatchDicList({ codes: ["yz_dw_dwlx", "yz_dw_dwzy", "yz_ry_ryzy", "yz_ry_tszynl"] });
        if (res) {
          this.selectOptions.teamType = res.yz_dw_dwlx;
          this.selectOptions.teamMajor = res.yz_dw_dwzy;
          this.selectOptions.memberMajor = res.yz_ry_ryzy;
          this.selectOptions.memberAbilityName = res.yz_ry_tszynl;
        }
      } else if (this.applyType == 2) {
        const res = await getBatchDicList({ codes: ["yz_cl_clxz", "dic_clyt", "dic_cllx"] });
        if (res) {
          this.selectOptions.vehicleProperties = res.yz_cl_clxz;
          this.selectOptions.vehicleUsage = res.dic_clyt;
          this.selectOptions.vehicleType = res.dic_cllx;
        }
      } else if (this.applyType == 3) {
        const res = await getBatchDicList({ codes: ["yz_zb_zbdl", "dic_zbxl"] });
        if (res) {
          this.selectOptions.zbLargeCategory = res.yz_zb_zbdl;
          this.selectOptions.zbSmallCategory = res.dic_zbxl;
        }
        GetListEquipmentType({ type: "modelParameters" }).then(res => {
          this.selectOptions.parameters = res.map(item => {
            return {
              dicName: item.name,
              id: item.code
            };
          });
        });
      } else if (this.applyType == 4) {
        const res = await getBatchDicList({ codes: ["dic-wzdl", "dic-wzzl", "dic-wzxl"] });
        if (res) {
          this.selectOptions.wzLargeCategory = res["dic-wzdl"];
          this.selectOptions.middleCategory = res["dic-wzzl"];
          this.selectOptions.wzSmallCategory = res["dic-wzxl"];
        }
      }
    },
    handleBtn(item) {
      this[item.id](item);
    },
    //  提交 / 保存
    submit(item) {
      let url = "";
      if (item.name === "提交") {
        url = "submit";
      } else {
        url = "save";
      }
      this.$refs.dialogForm.validate((valid) => {
        if (valid) {
          this.SaveOrSubmitForm(this.dialogForm, url);
        } else {
          return false;
        }
      });
    },
    async SaveOrSubmitForm(formName, url) {
      const parmas = {
        sourceInfo: this.mldName, // 命令单名称
        sourceInfoId: formName.sourceInfoId,
        resourceApplyName: formName.resourceApplyName,
        applyUnit: formName.applyUnit,
        applyUnitId: typeof (formName.applyUnitId) === "object" ? formName.applyUnitId[formName.applyUnitId.length - 1] : formName.applyUnitId || "",
        applyEvel: formName.applyEvel,
        acceptUnit: formName.acceptUnit,
        acceptUnitId: typeof (formName.acceptUnitId) === "object" ? formName.acceptUnitId[formName.acceptUnitId.length - 1] : formName.acceptUnitId || "",
        peopleCount: formName.peopleCount,
        destination: formName.destination,
        expectArrivalTime: formName.expectArrivalTime,
        contact: formName.contact,
        contactId: formName.contactId,
        contactWay: formName.contactWay,
        oApprovalId: formName.oApprovalId,
        oApprovalName: formName.oApprovalName,
        applyDescription: formName.applyDescription,
        applyType: this.applyType
      };
      if (this.applyType === 1) {
        parmas.applyResourceTeamDetail = formName.tableData;
      } else if (this.applyType === 2) {
        parmas.applyResourceVehicleDetail = formName.tableData;
      } else if (this.applyType === 3) {
        parmas.applyResourceEquipDetail = formName.tableData;
      } else if (this.applyType === 4) {
        parmas.applyResourceSuppliesDetail = formName.tableData;
      }
      if (this.addOredit === 0) { // 新增
        const res = await SaveOrSubmit(parmas, url);
        if (res) {
          this.$message({
            message: "操作成功",
            type: "success"
          });
        }
      } else if (this.addOredit === 1) { // 编辑修改
        parmas.id = formName.id;
        if (url === "save") {
          const res = await ResourceUpdate(parmas);
          if (res) {
            this.$message({
              message: "保存成功",
              type: "success"
            });
          }
        } else if (url === "submit") {
          const res = await SaveOrSubmit(parmas, url);
          if (res) {
            this.$message({
              message: "操作成功",
              type: "success"
            });
          }
        }
      }
      this.requestDialog.dialogConfig.isShow = false;
      this.$refs.dialogForm.resetFields();
      this.GetRequestLists();
    },


    // 工作流提交
    // gzlSubmit(bizKey, variable) {
    //   const data = {
    //     bizKey,
    //     flowKey: "team_resource_002",
    //     taskId: "task1",
    //     callbackUrl: "/emergency/emergencyResourceAllocation/handleFlow",
    //     idea: "1",
    //     variable
    //   };
    //   const successCallBack = () => {
    //     this.$message({
    //       message: "操作成功",
    //       type: "success"
    //     });
    //     this.GetRequestLists();
    //   };
    //   flowSubmit(data, successCallBack, "提交", true);
    // },

    // 工作流审批
    // gzlAudit(type, variable) {
    //   const data = {
    //     bizKey: this.requestListId,
    //     flowKey: "team_resource_002",
    //     taskId: "task2",
    //     callbackUrl: "/emergency/emergencyResourceAllocation/handleFlow",
    //     idea: type === 3 ? "1" : "0",
    //     variable,
    //     ideaMsg: this.dialogForm.approvalOpinion ? this.dialogForm.approvalOpinion : type === 3 ? "同意" : "驳回"
    //   };
    //   const successCallBack = () => {
    //     this.$message({
    //       message: `${type === 3 ? "审核" : "驳回"}成功`,
    //       type: "success"
    //     });
    //     this.GetRequestLists();
    //   };
    //   if (type === 3) {
    //     flowSubmit(data, successCallBack, "审核", true);
    //   } else {
    //     flowSubmit(data, successCallBack, "审核", false);
    //   }
    // },

    cancel() {
      this.$refs.dialogForm.resetFields();
      if (this.applyType === 1) {
        this.requestDialog = TeamFormDialog(this);
        this.dialogForm.tableData = this.requestDialog.formConfig3.table.tableData;
      } else if (this.applyType === 2) {
        this.requestDialog = CarFormDialog(this);
        this.dialogForm.tableData = this.requestDialog.formConfig3.table.tableData;
      } else if (this.applyType === 3) {
        this.requestDialog = EquipmentFormDialog(this);
        this.dialogForm.tableData = this.requestDialog.formConfig3.table.tableData;
      } else if (this.applyType === 4) {
        this.requestDialog = MaterialFormDialog(this);
        this.dialogForm.tableData = this.requestDialog.formConfig3.table.tableData;
      }
      this.requestDialog.dialogConfig.isShow = false;
    },
    // 设置页码
    handleSizeChange(val, form) {
      this.pageNum = val["current-page"];
      this.pageSize = val["page-size"];
      this.onSubmit(form);
    },
    onActionClick(item) {
      this[item.id](); // 调用列表按钮对应方法
    },
    // 新增
    dialogVisible() {
      this.addOredit = 0;
      this.requestDialog.dialogConfig.isShow = true;
      getAccountOrgById({ ssbmId: this.ssbmId }).then(res => { // 联系人
        const option = res.map((i) => {
          return {
            label: i.realName,
            value: i.id
          };
        });
        this.Usersoptions = res;
        this.requestDialog.formConfig2.formData[7].options = option;
        this.requestDialog.formConfig4.formData[0].options = option;
      });
      this.$set(this.dialogForm, "applyUnit", this.UserInfo.userUnit);
      this.$set(this.dialogForm, "applyUnitId", this.orgId);
      this.$set(this.dialogForm, "creator", this.UserInfo.userName);
      this.$set(this.dialogForm, "creatorUnit", this.dwbmName);
      this.$set(this.dialogForm, "createTime", showTime(new Date()));
      this.getFormInput();
      this.requestDialog.disableKeys = bianji;
      this.requestDialog.dialogConfig.btnList = [
        {
          name: "提交",
          type: "primary",
          id: "submit",
          size: "small"
        },
        {
          name: "保存",
          id: "submit",
          size: "small"
        },
        {
          name: "取消",
          id: "cancel",
          size: "small"
        }
      ];

    },
    changeMld(val) {
      let obj = {};
      obj = this.requestDialog.formConfig1.formData[0].options.find((item) => { // 命令单数据
        return item.value === val; // 筛选出匹配数据
      });
      this.mldName = obj.label;
    },
    handleCascaderChange(item, nowId) {
      if (item.label === "申请单位") {
        if (nowId) {
          console.log("申请单位ID", nowId);
          // getAccountByOrg({ orgId: nowId }).then(res => {
          //   const option = res.map((i) => {
          //     return {
          //       label: i.realName,
          //       value: i.userId
          //     };
          //   });
          //   this.Usersoptions = res;
          //     this.requestDialog.formConfig2.formData[7].options = option;
          // });
        }
      }
    },
    changeLxr(val, item) {
      if (item.label === "联系人") {
        let obj = {};
        obj = this.Usersoptions.find((s) => { // 命令单数据
          return s.id == val; // 筛选出匹配数据
        });
        this.$set(this.$refs.formComponent2.form, "contactWay", obj.phone);
      }
    },
    async GetApplyDetails(id) {
      const res = await GetApplyDetail({ id });
      this.dialogForm = res;
      let bumenId = "";
      if (res.applyStatus === 1 || res.applyStatus === 4) {
        bumenId = this.ssbmId; // 新增选择本部门的人审批
      } else if (res.applyStatus === 2) {
        bumenId = res.acceptUnitId; // 第一次审批后，选择受理部门的人审批
        if (!res.approvalUser) {
          this.$set(this.dialogForm, "approvalUser", this.UserInfo.userName);
          this.$set(this.dialogForm, "approvalDept", this.dwbmName);
          this.$set(this.dialogForm, "approvalTime", showTime(new Date()));
        }
      } else if (res.applyStatus === 5) {
        shenpi.push("approvalOpinion");
        if (!res.tApprovalDept) {
          this.$set(this.dialogForm, "tApprovalUser", this.UserInfo.userName);
          this.$set(this.dialogForm, "tApprovalDept", this.dwbmName);
          this.$set(this.dialogForm, "tApprovalTime", showTime(new Date()));
        }
      }
      //  根据部门匹配联系人
      getAccountOrgById({ ssbmId: bumenId }).then(datas => {
        const option = datas.map((item) => {
          return {
            label: item.realName,
            value: item.id
          };
        });
        this.Usersoptions = datas;
        this.requestDialog.formConfig2.formData[7].options = option;
        if (res.applyStatus === 1 || res.applyStatus === 4) {
          this.requestDialog.formConfig4.formData[0].options = option;
        } else if (res.applyStatus === 2) {
          this.requestDialog.formConfig5.formData[0].options = option;
        }
      });

      if (this.applyType === 1) {
        this.dialogForm.tableData = res.applyResourceTeamDetail;
      } else if (this.applyType === 2) {
        this.dialogForm.tableData = res.applyResourceVehicleDetail;
      } else if (this.applyType === 3) {
        this.dialogForm.tableData = res.applyResourceEquipDetail;
      } else if (this.applyType === 4) {
        this.dialogForm.tableData = res.applyResourceSuppliesDetail;
      }
    },

    // 编辑
    async handleEdit(id) {
      this.addOredit = 1;
      this.requestDialog.dialogConfig.isShow = true;
      this.getFormInput();
      this.GetApplyDetails(id);
      this.requestDialog.disableKeys = bianji;
      this.requestDialog.dialogConfig.btnList = [
        {
          name: "提交",
          type: "primary",
          id: "submit",
          size: "small"
        },
        {
          name: "保存",
          id: "submit",
          size: "small"
        },
        {
          name: "取消",
          id: "cancel",
          size: "small"
        }
      ];
    },
    // 审批
    async Approval(id, applyStatus) {
      this.applyStatus = applyStatus;
      this.requestListId = id;
      this.requestDialog.rules = {};
      this.requestDialog.titleConfig = [
        {
          title: "信息来源",
          name: "1",
          slot: "slot1"
        },
        {
          title: "申请信息",
          name: "2",
          slot: "slot2"
        },
        {
          title: "需求明细表",
          name: "3",
          slot: "slot3"
        },
        {
          title: "填报信息",
          name: "4",
          slot: "slot4"
        },
        {
          title: "申请单位审批信息",
          name: "5",
          slot: "slot5"
        }
      ];
      if (applyStatus === 5) {
        this.requestDialog.titleConfig.push({
          title: "受理单位审批信息",
          name: "6",
          slot: "slot6"
        });
        this.requestDialog.formConfig4.formData.splice(0, 1);
        this.requestDialog.formConfig5.formData.splice(0, 1);
      } else if (applyStatus === 2) {
        this.requestDialog.rules = {
          tApprovalId: [
            { required: true, message: "下一步审批人", trigger: "change" }
          ]
        };
        this.requestDialog.formConfig4.formData.splice(0, 1);
      }

      this.requestDialog.dialogConfig.isShow = true;
      this.requestDialog.formConfig3.table.columns.pop();
      this.getFormInput(); // 获取表单接口
      this.GetApplyDetails(id);
      this.requestDialog.disableKeys = shenpi;
      this.requestDialog.dialogConfig.btnList = [
        {
          name: "同意",
          type: "primary",
          id: "Approve",
          approveSign: "pass",
          size: "small"
        },
        {
          name: "驳回",
          id: "Approve",
          approveSign: "reject",
          size: "small"
        },
        {
          name: "取消",
          id: "cancel",
          size: "small"
        }
      ];

    },
    // 审批
    async Approve(item) {
      let res = "";
      let approveSign = "";
      if (item.approveSign === "pass") {
        approveSign = "pass";
      } else {
        approveSign = "reject";
      }
      if (this.applyStatus === 2) {
        if (item.approveSign === "pass") {
          this.$refs.dialogForm.validateField(["tApprovalId"], async (valid) => {
            if (!valid) {
              res = await DispacthApproveOne({
                approvalOpinion: this.dialogForm.approvalOpinion,
                approveSign: approveSign,
                tApprovalId: this.dialogForm.tApprovalId || "",
                tApprovalName: this.dialogForm.tApprovalName || "",
                id: this.requestListId
              });
              if (res) {
                this.$message({
                  message: "审核成功",
                  type: "success"
                });
              }
              this.requestDialog.dialogConfig.isShow = false;
              this.GetRequestLists();
            }
          });
        } else {
          res = await DispacthApproveOne({
            approvalOpinion: this.dialogForm.approvalOpinion,
            approveSign: approveSign,
            tApprovalId: this.dialogForm.tApprovalId || "",
            tApprovalName: this.dialogForm.tApprovalName || "",
            id: this.requestListId
          });
          if (res) {
            this.$message({
              message: "审核成功",
              type: "success"
            });
          }
          this.requestDialog.dialogConfig.isShow = false;
          this.GetRequestLists();
        }
      } else {
        res = await DispacthApproveTwo({
          tApprovalOpintion: this.dialogForm.tApprovalOpintion,
          approveSign: approveSign,
          id: this.requestListId
        });
        if (res) {
          this.$message({
            message: "审核成功",
            type: "success"
          });
        }
        this.requestDialog.dialogConfig.isShow = false;
        this.GetRequestLists();
      }
    },
    // 删除
    async deleted(id) {
      this.$confirm("确定删除吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        ResourceDeleted({ id }).then(res => {
          if (res) {
            this.$message({
              message: "删除成功",
              type: "success"
            });
            this.GetRequestLists();
          }
        });
      }).catch(() => {

      });
    },
    handleSelectTree(arg, item) {
      if (item.id === "acceptUnit") {
        this.$set(this.form, "acceptUnitId", arg[0].id);
        this.$set(this.form, "acceptUnit", arg[0].orgName);
      } else if (item.id === "applyUnit") {
        this.$set(this.form, "applyUnitId", arg[0].id);
        this.$set(this.form, "applyUnit", arg[0].orgName);
      }
    },
    // 查询
    async onSubmit(val) {
      const parmas = {
        pageNum: this.pageNum,
        pageSize: this.pageSize,
        applyType: this.applyType, // 资源类型
        // ...val
        sourceInfo: val.sourceInfo, // 响应命令单
        resourceApplyName: val.resourceApplyName, // 资源申请单
        acceptUnitId: val.acceptUnitId, // 受理单位及部门
        applyUnitId: val.applyUnitId, // 申请单位
        applyStartTime: val.applyTime ? val.applyTime[0] : "", // 开始时间
        applyEndTime: val.applyTime ? val.applyTime[1] : "", // 结束时间
        applyEvel: val.applyEvel, // 需求等级
        applyStatus: val.applyStatus // 状态
      };
      const res = await GetRequestList(parmas);
      this.table.tableData = res.data;
      this.paginationAtrrs.total = res.total;
    },
    resetForm() {
      this.form = this.$options.data().form;
      this.GetRequestLists();
    },
    detailList(id) {
      this.$router.push({
        name: "ResourceRequestDetail",
        query: { id: id, type: this.applyType }
      });
    },
    goSourceInfo(id) {
      this.$router.push({
        name: "EmergencyResponseinfo",
        query: { id }
      });
    }
  }
};
</script>

<style scoped lang="less">
@import "../../../../assets/style/pop-upNotification.less";
@import "../../../../assets/style/ComponentStyle.less";
@import "../../../../assets/style/common.less";

.EmergencyList {
  height: 100%;
}

:deep(.el-breadcrumb__inner.is-link) {
  font-weight: 100;
  color: #fff;
}

.EmergencyList :deep(.el-breadcrumb__item:last-child .el-breadcrumb__inner) {
  color: #3270ff;
}

.box {
  flex: 1;
  display: flex;
  flex-direction: column;
  margin-top: 15px;
  background-color: #fff;
  border-radius: 4px;
  padding: 10px;
  box-sizing: border-box;
}

.team-pag {
  float: right;
  margin-top: 10px;

  div {
    line-height: 35px;
  }
}

.flex {
  .flex-warp {
    flex-wrap: wrap;

    :deep(.el-form-item) {
      width: 50%;
    }
  }

  :deep(.el-form-item) {
    margin: 10px 0;
  }
}

:deep(.el-input-number.is-controls-right.inventoryInput) {
  :deep(.el-input__inner) {
    border: none;
    width: 80px;
  }
}

:deep(.el-table__cell) {

  .el-input__inner,
  .el-form-item__content,
  .el-input-number {
    width: 100%;
  }

  .el-form-item {
    width: 100%;
    margin-bottom: 0;
    margin-right: 0;
  }
}

:deep(.el-dialog) {
  .el-table .el-table__cell {
    padding: 3px 0;
  }

  .el-form-item__content {
    font-size: 16px;
  }
}

.tableDiv {
  :deep(.leftTopBtn) {
    height: 0;
    margin-bottom: 0;
  }
}
</style>
